home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / cert / trk3_eg / ini / ini.frm (.txt) next >
Encoding:
Visual Basic Form  |  1994-11-29  |  6.0 KB  |  177 lines

  1. VERSION 2.00
  2. Begin Form frmINI 
  3.    Caption         =   "Read/Write to INI"
  4.    ClientHeight    =   3465
  5.    ClientLeft      =   1710
  6.    ClientTop       =   1545
  7.    ClientWidth     =   4875
  8.    Height          =   3870
  9.    Left            =   1650
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3465
  13.    ScaleWidth      =   4875
  14.    Top             =   1200
  15.    Width           =   4995
  16.    Begin TextBox txtsample 
  17.       Height          =   285
  18.       Left            =   600
  19.       MaxLength       =   15
  20.       TabIndex        =   9
  21.       Top             =   360
  22.       Width           =   2415
  23.    End
  24.    Begin CommandButton cmdExit 
  25.       Caption         =   "Exit"
  26.       Height          =   495
  27.       Left            =   3480
  28.       TabIndex        =   8
  29.       Top             =   2760
  30.       Width           =   1215
  31.    End
  32.    Begin CommandButton cmdRead 
  33.       Caption         =   "Read"
  34.       Height          =   495
  35.       Left            =   3480
  36.       TabIndex        =   7
  37.       Top             =   1800
  38.       Width           =   1215
  39.    End
  40.    Begin CommandButton cmdWrite 
  41.       BackColor       =   &H00000000&
  42.       Caption         =   "Write"
  43.       Height          =   495
  44.       Left            =   3480
  45.       TabIndex        =   6
  46.       Top             =   960
  47.       Width           =   1215
  48.    End
  49.    Begin CheckBox chkBlue 
  50.       Caption         =   "Blue"
  51.       Height          =   495
  52.       Left            =   2160
  53.       TabIndex        =   5
  54.       Top             =   2640
  55.       Width           =   1215
  56.    End
  57.    Begin CheckBox chkGreen 
  58.       Caption         =   "Green"
  59.       Height          =   495
  60.       Left            =   2160
  61.       TabIndex        =   4
  62.       Top             =   1800
  63.       Width           =   1215
  64.    End
  65.    Begin CheckBox chkRed 
  66.       Caption         =   "Red"
  67.       Height          =   495
  68.       Left            =   2160
  69.       TabIndex        =   3
  70.       Top             =   960
  71.       Width           =   1215
  72.    End
  73.    Begin Label lblSampletxt 
  74.       Caption         =   "Sample text"
  75.       Height          =   255
  76.       Left            =   600
  77.       TabIndex        =   10
  78.       Top             =   120
  79.       Width           =   1815
  80.    End
  81.    Begin Label lblBlue 
  82.       BackColor       =   &H00FF0000&
  83.       Height          =   495
  84.       Left            =   600
  85.       TabIndex        =   2
  86.       Top             =   2640
  87.       Visible         =   0   'False
  88.       Width           =   1215
  89.    End
  90.    Begin Label lblGreen 
  91.       BackColor       =   &H0000FF00&
  92.       Height          =   495
  93.       Left            =   600
  94.       TabIndex        =   1
  95.       Top             =   1800
  96.       Visible         =   0   'False
  97.       Width           =   1215
  98.    End
  99.    Begin Label lblRed 
  100.       BackColor       =   &H000000FF&
  101.       Height          =   495
  102.       Left            =   600
  103.       TabIndex        =   0
  104.       Top             =   960
  105.       Visible         =   0   'False
  106.       Width           =   1215
  107.    End
  108. Option Explicit
  109. Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer
  110. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  111. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, lpKeyName As Any, lpString As Any, ByVal lplFileName As String) As Integer
  112. 'Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As string, byVal lpString As string, ByVal lplFileName As String) As Integer
  113. 'The second WritePrivateProfileString seems to work better than the Declared copied from the Help file.
  114. '    rc = WritePrivateProfileString(Sectionname, keyname, keyvalue, filename)
  115. Sub chkBlue_Click ()
  116. If ChkBlue.Value = 1 Then
  117.     lblBlue.Visible = True
  118.     lblBlue.Visible = False
  119. End If
  120. End Sub
  121. Sub chkGreen_Click ()
  122. If ChkGreen.Value = 1 Then
  123.     lblGreen.Visible = True
  124.     lblGreen.Visible = False
  125. End If
  126. End Sub
  127. Sub chkRed_Click ()
  128. If ChkRed.Value = 1 Then
  129.     lblRed.Visible = True
  130.     lblRed.Visible = False
  131. End If
  132. End Sub
  133. Sub cmdExit_Click ()
  134.     End
  135. End Sub
  136. Sub cmdRead_Click ()
  137.     Dim rc As Integer
  138.     Dim keyvalue As String
  139.     Dim keydefault As String
  140.     Dim keyname As String
  141.     Dim Sectionname As String
  142.     Dim filename As String
  143.     filename = "Marc.INI"
  144.     Sectionname = "INI Sample"
  145.     keyname = "Sample Text"
  146.     keydefault = "INI Sample"
  147.     keyvalue = String$(16, 0)
  148.     rc = GetPrivateProfileString(Sectionname, keyname, keydefault, keyvalue, Len(keyvalue), filename)
  149.     txtSample = keyvalue
  150.     ChkRed.Value = GetPrivateProfileInt(Sectionname, "Red", 0, filename)
  151.     ChkGreen.Value = GetPrivateProfileInt(Sectionname, "Green", 0, filename)
  152.     ChkBlue.Value = GetPrivateProfileInt(Sectionname, "Blue", 0, filename)
  153.  End Sub
  154. Sub cmdWrite_Click ()
  155.     Dim rc As Integer
  156.     Dim keyname As String
  157.     Dim keyvalue As String
  158.     Dim Sectionname As String
  159.     Dim filename As String
  160.     Sectionname = "INI Sample"
  161.     filename = "Marc.ini"
  162.     keyname = "Sample Text"
  163.     keyvalue = txtSample
  164.     keyname = "Sample Text"
  165.     keyvalue = txtSample.Text
  166.     rc = WritePrivateProfileString(Sectionname, ByVal keyname, ByVal keyvalue, filename)
  167.     keyname = "Red"
  168.     keyvalue = Str$(ChkRed.Value)
  169.     rc = WritePrivateProfileString(Sectionname, ByVal keyname, ByVal keyvalue, filename)
  170.     keyname = "Green"
  171.     keyvalue = Str$(ChkGreen.Value)
  172.     rc = WritePrivateProfileString(Sectionname, ByVal keyname, ByVal keyvalue, filename)
  173.     keyname = "Blue"
  174.     keyvalue = Str$(ChkBlue.Value)
  175.     rc = WritePrivateProfileString(Sectionname, ByVal keyname, ByVal keyvalue, filename)
  176. End Sub
  177.